<template>
	<view class="page bg-fff">
		<view class="searchInputWrap bg-fff">
			<up-search v-model="keyword" placeholder="输入您想查看的楼盘名称" height="40" shape="round" borderColor="#E5E5E5" :showAction="false" bgColor="#FFFFFF" @change="clickSearch" @search="clickSearch"></up-search>
		</view>

		<block v-if="videoList.length > 0">
			<video-item :list="videoList"></video-item>
			<u-loadmore :status="loadingType" />
		</block>
		<up-empty text="暂无数据" mode="list" marginTop="100" v-if="videoList.length === 0 && loadingType === 'nomore'"></up-empty>
		<up-gap height="40"></up-gap>
	</view>
</template>

<script>
	import { loadVideoProducts } from '@/common/api/houses';
	export default {
		data() {
			return {
                keyword: '',
				cityCode: '',
				videoList:[],
				next: '',
				loadingType: 'loadmore'
			}
		},
		onLoad(options) {
			this.cityCode = options.city || '';
			uni.$check_and_login(this.loadData);
		},
		onPullDownRefresh() {
			this.loadData(true)
		},
		onReachBottom(){
			this.loadData()
		},
		onShareAppMessage(res) {
			return {
				title: '户型全景实拍，快来围观',
				path: `/pages/product/video/index?city=${this.cityCode}`,
			}
		},
        //#ifdef MP-WEIXIN
        onShareTimeline() {
            return {
                title: '户型全景实拍，快来围观',
                query: `city=${this.cityCode}`
            }
        },
        //#endif
		methods: {
			//点击去搜索
			async clickSearch(){
				await this.loadData(true);
			},

			//加载数据
			async loadData(isRefresh=false){
				if(isRefresh){
					this.loadingType = 'loadmore';
					this.next = '';
				}
				if(this.loadingType === 'loading' || this.loadingType === 'nomore')return;
				uni.showLoading({
					title: '数据加载中',
					mask: true
				})
				this.loadingType = 'loading';
				let url = this.next == '' || this.videoList.length == 0 ? `/product/mall/api/video/all?query=${this.keyword}` : this.next;
				try{
					let {status, detail} = await loadVideoProducts(url, {});
					if(status !== 0){
						uni.$u.toast(detail);
						return;
					}
					if(isRefresh){
						this.videoList = detail.results;
					}else{
						this.videoList.push(...detail.results);
					}
					this.next = detail.next;
					this.loadingType = this.next ? 'loadmore' : 'nomore';
					uni.stopPullDownRefresh();
					uni.hideLoading()
				}catch(err){
					uni.stopPullDownRefresh();
					uni.hideLoading()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		padding: 0 30rpx;
		min-height: 100vh;
		.searchInputWrap{
			position: sticky;
			top: 0;
			z-index: 100;
			padding: 30rpx 0;
		}
	}
</style>